{extend name='extra@admin/content'}

{block name="button"}
<div class="nowrap pull-right" style="margin-top:10px">
    {if auth("$classuri/add_edit_material")}
    <button data-modal='{:url("$classuri/add_edit_material")}' data-title="添加原材料" class='layui-btn layui-btn-small'>
        <i class='fa fa-plus'></i> 添加原材料
    </button>
    {/if}
    <!--{if auth("kuguan/materialpeifang/create_jinhuo_peifang_order")}-->
    <!--<button data-modal='{:url("kuguan/materialpeifang/create_jinhuo_peifang_order")}?type=1' data-title="配方进货" class='layui-btn layui-btn-small'>-->
        <!--<i class='fa fa-plus'></i> 配方进货-->
    <!--</button>-->
    <!--{/if}-->
    {if auth("$classuri/create_jinhuo_order")}
    <button data-modal='{:url("$classuri/create_jinhuo_order")}?type=1' data-title="原料进货" class='layui-btn layui-btn-small'>
        <i class='fa fa-plus'></i> 原料进货
    </button>
    {/if}
    <!--{if auth("kuguan/materialpeifang/create_shengchan_peifang_order")}-->
    <!--<button data-modal='{:url("kuguan/materialpeifang/create_shengchan_peifang_order")}?type=1' data-title="配方生产" class='layui-btn layui-btn-small'>-->
        <!--<i class='fa fa-plus'></i> 配方生产-->
    <!--</button>-->
    <!--{/if}-->
    {if auth("$classuri/create_jinhuo_order")}
    <button data-modal='{:url("$classuri/create_shengchan_order")}?type=2' data-title="原料生产" class='layui-btn layui-btn-small layui-btn-danger'>
        <i class='fa fa-plus'></i> 原料生产
    </button>
    {/if}
    <!--{if auth("$classuri/create_purchase_order")}-->
    <!--<button type="button"  href="javascript:void(0)" class='layui-btn layui-btn-small layui-btn-danger' onclick="check_order(1)">-->
    <!--<i class='fa fa-plus'></i> 进货-->
    <!--</button>-->
    <!--{/if}-->
    <!-- {if auth("$classuri/create_purchase_order")}
    <button type="button"  href="javascript:void(0)" class='layui-btn layui-btn-small layui-btn-danger' onclick="check_order(2)">
        <i class='fa fa-plus'></i> 生产
    </button>
    {/if} -->
    {if auth("$classuri/add_pecipe")}
    <button data-open='{:url("$classuri/warn_detail")}' href="javascript:void(0)" class='layui-btn layui-btn-small layui-btn-danger'>
        <i class='fa fa-exclamation-circle'></i> （{$num}）原料即将缺货
    </button>
    {/if}
    {if !empty($list)}
        {if auth("kuguan/export/export_material")}
        <a href='{:url("store/export/export_material")}?name={$Think.get.name}&cate_1={$Think.get.cate_1}&cate_2={$Think.get.cate_2}&cate_3={$Think.get.cate_3}' class="layui-btn layui-btn-small" style="text-decoration:none"><i class="fa fa-mail-forward"></i>
            导出
        </a>
        {/if}
    {else /}
        <a href="javascript:;" onclick="no_export();" class="layui-btn layui-btn-small " style="text-decoration:none;"><i class='fa fa fa-mail-forward'></i> 导出</a>
    {/if}

    <!--<button data-open='{:url("$classuri/material_category")}' data-title="材料分类" class='layui-btn layui-btn-small'>-->
    <!--<i class='fa fa-plus'></i> 材料分类-->
    <!--</button>-->
    <!--<button data-modal='{:url("$classuri/add_material_category")}' data-title="添加分类" class='layui-btn layui-btn-small'>-->
    <!--<i class='fa fa-plus'></i> 添加分类-->
    <!--</button>-->

</div>
{/block}

{block name="content"}

<!-- 表单搜索 开始 -->
<form class="animated form-search" action="__SELF__" onsubmit="return false" method="get">
    <div class="col-xs-2">
        <div class="form-group">
            <select name="cate_1"  lay-filter="export" class="input-sm form-control">
                <option value="">- 选择一级分类 -</option>
                {foreach category_one as $v1}
                <option value="{$v1.name}" {if $Think.get.cate_1 eq $v1.id} selected {/if}>{$v1.name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="col-xs-2">
        <div class="form-group">
            <select name="cate_2"  lay-filter="export" class="input-sm form-control">
                <option value="">- 选择二级分类 -</option>
                {foreach category_two as $v2}
                <option value="{$v2.name}" {if $Think.get.cate_2 eq $v2.id} selected {/if}>{$v2.name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="col-xs-2">
        <div class="form-group">
            <select name="cate_3"  lay-filter="export" class="input-sm form-control">
                <option value="">- 选择三级分类 -</option>
                {foreach category_three as $v3}
                <option value="{$v3.name}" {if $Think.get.cate_3 eq $v3.id} selected {/if}>{$v3.name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">材料名称</label>
        <div class="layui-input-inline">
            <input name="name" value="{$Think.get.name|default=''}" placeholder="请输入材料名称" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i> 搜 索</button>
    </div>

</form>
<!-- 表单搜索 结束 -->

<form onsubmit="return false;" data-auto="true" method="post">
    {if empty($list)}
    <p class="help-block text-center well">没 有 记 录 哦！</p>
    {else}
    <input type="hidden" value="resort" name="action"/>
    <table class="layui-table" lay-skin="line" lay-size="sm">
        <thead>
            <tr>
                <th class='list-table-check-td'>
                    <input data-none-auto="" data-check-target='.list-check-box' type='checkbox'/>
                </th>
                <th class='text-left nowrap'>物料编码</th>
                <th class='text-left nowrap'>条码</th>
                <th class='text-left nowrap'>材料名称<!--<span style="color:red;">(即将缺货 - {$num})</span>--></th>
                <th class='text-left nowrap'>标准售价</th>
                <th class='text-left nowrap'>单位</th>
                <th class='text-left nowrap'>库存</th>
                <th class='text-left nowrap'>安全库存</th>
              <!--<th class='text-left nowrap'>单价</th>-->
                <th class='text-left nowrap'>添加时间</th>
                <th class='text-left nowrap'>操作</th>
            </tr>
        </thead>
        <tbody>
            {foreach $list as $key=>$vo}
            <tr>
                <td class='list-table-check-td'>
                    <input class="list-check-box" value='{$vo.id}' type='checkbox'/>
                </td>
                <td class='text-left nowrap'>
                    {$vo.code}
                </td>
                <td class='text-left nowrap'>
                    {$vo.tiaoma}
                </td>
                <td class='text-left nowrap'>
                    <!--{if condition="$vo.stock lt $vo.warn_stock"}-->
                    <!--<span style="color:red;">{$vo.name}</span>-->
                    <!--{/if}-->
                    <span>{$vo.name}</span>
                </td>
                <td class='text-left nowrap'>
                    {$vo.price}
                </td>
                <td class='text-left nowrap'>
                    {$vo.unit}
                </td>
                <td class='text-left nowrap'>
                    {if condition="!empty($vo.stock)"}
                    {$vo.stock}
                    {else /}
                    0
                    {/if}
                </td>
                <td class='text-left nowrap'>
                    <span class="text-explode">|</span>
                    {if condition="!empty($vo.warn_stock)"}
                    {$vo.warn_stock}
                    {else /}
                    暂未设置
                    {/if}
                    {if auth("$classuri/change_warn")}
                        <span class="text-explode">|</span>
                        <a data-modal='{:url("$classuri/change_warn")}?id={$vo.id}' data-title="设置安全库存-{$vo.name}"
                           href="javascript:void(0)">设置</a>
                    {/if}
                </td>
              <!--<td class='text-left nowrap'>-->
              <!--{$vo.price}-->
              <!--</td>-->
                <td class='text-left nowrap'>
                    {$vo.addtime|date="Y-m-d",###}
                </td>
                <td class='text-left nowrap'>
                    {if auth("$classuri/add_edit_material")}
                        <span class="text-explode">|</span>
                        <a data-modal='{:url("$classuri/add_edit_material")}?id={$vo.id}' href="javascript:void(0)" title="编辑">编辑</a>
                    {/if}
                    {if auth("$classuri/change_stock")}
                        <span class="text-explode">|</span>
                        <a data-modal='{:url("$classuri/change_stock")}?id={$vo.id}' href="javascript:void(0)" title="变更库存">变更库存</a>
                    {/if}
                    {if auth("store/materialstock/material_stock_log")}
                        <span class="text-explode">|</span>
                        <a data-open='{:url("store/materialstock/material_stock_log")}?id={$vo.id}' href="javascript:void(0)" title="库存日志">库存日志</a>
                    {/if}
                    {if auth("$classuri/del_material")}
                        <span class="text-explode">|</span>
                        <a data-update="{$vo.id}" data-field='delete' data-action='{:url("$classuri/del_material")}'
                           href="javascript:void(0)" title="删除">删除</a>
                    {/if}
                </td>
            </tr>
            {/foreach}
        </tbody>
    </table>
    {if isset($page)}<p>{$page}</p>{/if}
    {/if}
    <script>
        window.laydate.render({range: true, elem: '#range-date', format: 'yyyy/MM/dd'});

        function check_order(type){
            var values = '';
            $.each($('input.list-check-box:checkbox'),function(){
                if(this.checked){
                    values += $(this).val()+",";
                }
            });
            if(values == ''){
                layer.msg();
//                layer.msg('添加原料重复，请去除重复的原料');
//                layer.alert('请选择需要订货的原料', {end: function(data){}, scrollbar: false});           //没有选择原料
                layer.msg('请选择需要操作的原料', {icon: 2, shade: this.shade, scrollbar: false, time: 1500, end: function(data){}, shadeClose: true});
                return false;
            }
            var spm = "{$Think.get.spm}";
            var dir =  "{:url('@admin')}#{:url('create_purchase_order')}?spm="+spm+"&ids="+values+"&type="+type;
            window.location.href=dir;
        }
        /**
         * 不能导信息
         */
        function no_export(){
            layer.msg('查询数据为空，不能导出数据',{icon: 2, time: 1500});
            return false;
        }

    </script>
</form>
{/block}